﻿using Desktop.Controls;
using Desktop.Dialogs;
using Desktop.Library;
using Microsoft.Win32;
using System.Threading;
using System.Windows;

namespace StoryWriter
{
    /// <summary>
    /// Interaction logic for StoryRibbon.xaml
    /// </summary>
    public partial class StoryRibbon : Ribbon
    {
        #region Constructors

        public StoryRibbon(Desktop.Controls.Application app)
            : base(app)
        {
            InitializeComponent();

            AddWorkspace("Dashboard", false, typeof(Dashboard));
            AddWorkspace("User Preferences", true, typeof(UserPreferences));
            AddWorkspace("Blog Maintenance", true, typeof(BlogMaintenance));
            AddWorkspace("HTML Test", true, typeof(HTMLTest));

            OpenWorkspace("Dashboard");
        }

        #endregion

        #region Event Handlers

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Desktop Files (*.dsk)|*.dsk";
            if (!dlg.ShowDialog().GetValueOrDefault(false))
            {
                return;
            }
            SessionManager.Save(dlg.FileName);
        }

        private void openButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Desktop Files (*.dsk)|*.dsk";
            if (!dlg.ShowDialog().GetValueOrDefault(false))
            {
                return;
            }
            SessionManager.Load(dlg.FileName);
        }

        private void preferencesButton_Click(object sender, RoutedEventArgs e)
        {
            OpenWorkspace("User Preferences");
        }

        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            /*
            LoginWindow.Login();
            if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                (Parent as MainWindow).loggedInAsLabel.DataContext = Thread.CurrentPrincipal.Identity;
                loginButton.Visibility = Visibility.Collapsed;
                logoutButton.Visibility = Visibility.Visible;
            }
            (Parent as MainWindow).application.RaiseEvent(new RoutedEventArgs(Desktop.Controls.Application.PrincipalChangedEvent, (Parent as MainWindow).application));
            */
        }

        private void logoutButton_Click(object sender, RoutedEventArgs e)
        {
            /*
            Thread.CurrentPrincipal = new GooglePrincipal(new GoogleIdentity());
            (Parent as MainWindow).loggedInAsLabel.DataContext = Thread.CurrentPrincipal.Identity;
            loginButton.Visibility = Visibility.Visible;
            logoutButton.Visibility = Visibility.Collapsed;
            (Parent as MainWindow).application.RaiseEvent(new RoutedEventArgs(Desktop.Controls.Application.PrincipalChangedEvent, (Parent as MainWindow).application));
            */
        }

        private void blogsButton_Click(object sender, RoutedEventArgs e)
        {
            OpenWorkspace("Blog Maintenance");
        }

        private void htmlTestButton_Click(object sender, RoutedEventArgs e)
        {
            OpenWorkspace("HTML Test");
        }

        #endregion
    }
}